#include "Client.h"
#include "Slot.h"



Client::Client(Table* _table){
  table = _table;
  cardX=0;
  cardY=0;
  suit=0;
  number=0;
  dragX=0;
  dragY=0;
  
  initializeDisplay();
}

void Client::initializeDisplay(){
  gameDisplay.drawBox(0,1, 78,36,0);
  for(int i = 0; i < 8; i++){
    p1Cards[i].setX(18 + 6*i);
    p1Cards[i].setY(27);
  }
  for(int i=0; i<2; i++){
    p2Cards[i].setX(8);
    p2Cards[i].setY(12 + 5*i);
    //p5Cards[i].setX(8);
    //p5Cards[i].setY(12+4*i);
  }
  for(int i=0; i<2; i++){
    p3Cards[i].setX(32 + 6*i);
    p3Cards[i].setY(4);
  }
  //sleep(1);
  for(int i=0; i<2; i++){
    p4Cards[i].setX(64);
    p4Cards[i].setY(12 + 5 *i);
  }
  //sleep 1;
  actives[0].setX(36);
  actives[0].setY(21);
  actives[1].setX(17);
  actives[1].setY(15);
  actives[2].setX(36);
  actives[2].setY(9);
  actives[3].setX(55);
  actives[3].setY(15);
  pillage.setX(32);
  pillage.setY(16);
  spoils.setX(40);
  spoils.setY(16);

 // actives[2].

  
 for(int i = 0; i < 10; i++){
    gameDisplay.displayCard(p1Cards[i].getX(),p1Cards[i].getY(), 99,i,0);
  } 
  gameDisplay.displayCard(p1Cards[8].getX(),p1Cards[8].getY(), 99,2,0);
  for(int i = 0; i < 2; i++){
    gameDisplay.displayCard(p2Cards[i].getX(),p2Cards[i].getY(), 99,1,0);
  } 
  for(int i = 0; i < 2; i++){
    gameDisplay.displayCard(p3Cards[i].getX(),p3Cards[i].getY(), 99,2,0);
  } 
  for(int i = 0; i < 2; i++){
    gameDisplay.displayCard(p4Cards[i].getX(),p4Cards[i].getY(), 99,5,0);
  } 
  for(int i=0; i<4; i++){
    gameDisplay.displayCard(actives[i].getX(),actives[i].getY(), 99,2,0);
  }


}


void Client::drawTable(Table* table){
  //gameDisplay.drawBox(0,1, 76,36,0);
  /*for(int i = 0; i < 10; i++){
    gameDisplay.displayCard(p1Cards[i].getX(),p1Cards[i].getY(), 1,i,0);
  } 
  gameDisplay.displayCard(p1Cards[8].getX(),p1Cards[8].getY(), 2,2,0);
  for(int i = 0; i < 2; i++){
    gameDisplay.displayCard(p2Cards[i].getX(),p2Cards[i].getY(), 2,1,0);
  } 
  for(int i = 0; i < 2; i++){
    gameDisplay.displayCard(p3Cards[i].getX(),p3Cards[i].getY(), 3,2,0);
  } 
  for(int i = 0; i < 2; i++){
    gameDisplay.displayCard(p4Cards[i].getX(),p4Cards[i].getY(), 4,5,0);
  } 
  for(int i=0; i<4; i++){
    gameDisplay.displayCard(actives[i].getX(),actives[i].getY(), 2,2,0);
  }*/

  //gameDisplay.displayCard(p1Cards[0].getX(),p1Cards[0].getY(), 1,1,1);
  //gameDisplay.displayCard((p1Cards.at(0)->getX()),(p1Cards.at(0)->getY()),1,1,10);
  //gameDisplay.displayCard(player1.at(1)->getX(),player1.at(1)->getY(),1,1,0);
  //gameDisplay.displayCard(20,10,2,2,1);
}

void Client::updateClient(Table* table){
  
  gameDisplay.updateScreen();
  // calls the game display to capture some input
  key = gameDisplay.captureInput();
  // calls the game display to capture some input
    
      // if a mouse event occurred
      if (key == -1) {
        // make a banner message
        messageString.str("");
        messageString << "A mouse event occurred x=" \
          << gameDisplay.getMouseEventX() << ", y=" \
          << gameDisplay.getMouseEventY() << ", bstate=" \
          << gameDisplay.getMouseEventButton();
        // display a banner message
        gameDisplay.bannerTop(messageString.str());
        // record the location of the mouse event
        clickX = gameDisplay.getMouseEventX();
        clickY = gameDisplay.getMouseEventY();
        // Some of the mouse click values are defined in display.h
        // check if it was a left click
        if (gameDisplay.getMouseEventButton()&LEFT_CLICK) {
      
        // check if it was a right click
        } else if (gameDisplay.getMouseEventButton()&RIGHT_CLICK) {
        }
     
    }

  drawTable(table);
  
}


